{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from jqdata import *\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 下载的代码\n",
    "code = '000001.XSHG'\n",
    "re_code = 'SH.000001'\n",
    "frequencys = {'1w': 'w', '1d': 'd', '30m': '30m' ,'5m': '5m'}\n",
    "pd_klines = None\n",
    "\n",
    "for f, re_f in frequencys.items():\n",
    "    klines = get_bars(code, 9999999, unit=f,fields=['date', 'open', 'close', 'high', 'low', 'volume'], include_now=False, df=True)\n",
    "    klines.loc[:, 'code'] = re_code\n",
    "    klines.loc[:, 'frequency'] = re_f\n",
    "    if pd_klines is None:\n",
    "        pd_klines = klines\n",
    "    else:\n",
    "        pd_klines = pd_klines.append(klines, ignore_index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd_klines.to_csv('stock.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "MarkDown菜单",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}